package com.sduty.lucene.analyzer;

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.Tokenizer;

import com.sduty.lucene.attribute.MyCharAttribute;
import com.sduty.lucene.tokenfilter.MyLowerCaseTokenFilter;
import com.sduty.lucene.tokenizer.MyWhitespaceTokenizer;

public class MyWhitespaceAnalyzer extends Analyzer{

	@Override
	protected TokenStreamComponents createComponents(String fieldName) {
		Tokenizer source = new MyWhitespaceTokenizer();
		TokenStream filter = new MyLowerCaseTokenFilter(source);
		return new TokenStreamComponents(source,filter);
	}
	
	public static void main(String[] args) {
		String text = "An AttributeSource contains a list of different AttributeImpls, and methods to add and get them. ";
		
		try {
			Analyzer analyzer = new MyWhitespaceAnalyzer();
			TokenStream ts = analyzer.tokenStream("title", text);
			MyCharAttribute att = ts.getAttribute(MyCharAttribute.class);
			ts.reset();
			while(ts.incrementToken()) {
				System.out.println(att.getString());
			}
			ts.end();
			analyzer.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		
	}

}
